import React from 'react';
import Api from 'Utils/api';
import Navigation from '../../Navigation';
import './index.scss';

class ServerPage extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      navigation: [
        {
          name: '最多跑一次',
          key: 'run_once',
        },
        {
          name: '食安地图',
          key: 'shiAn_map',
        },
        {
          name: '机构导航',
          key: 'market_institution_navigation',
        }
      ],
      navigation2: [
        {
          name: '最多跑一次',
          key: 'run_once',
        },
        {
          name: '机构导航',
          key: 'market_institution_navigation',
        }
      ],
      isShowMap: true,
    };
    this.mergeNavigation = ::this.mergeNavigation;
  }

  componentWillMount() {
    this.initMapStatus();
  }
  initMapStatus() {
    const api = new Api({
      method: 'GET',
      path: '/switch_maps',
      success: (res) => {
        this.setState({
          isShowMap: res.switch_value
        });
      }
    });
    api.run();
  }
  mergeNavigation() {
    const { isShowMap, navigation, navigation2 } = this.state;
    if (isShowMap) {
      return navigation;
    }
    return navigation2;
  }
  render() {
    return (
      <div className="content-wrapper" >
        <Navigation
          config={this.mergeNavigation()}
          defaultKey={'run_once'}
        />
        <div className="main-container" >
          {this.props.children}
        </div >
      </div >
    );
  }
}

export default ServerPage;
